package com.example.materialviewpagerdemo.util;

import android.content.Context;
import android.content.SharedPreferences;

public class SPHelper {
    SharedPreferences sharedPreferences;
    public SPHelper(Context context,String filename){
        sharedPreferences=context.getSharedPreferences(filename,Context.MODE_PRIVATE);

    }
    public static class VauleMap{
        String key;
        Object vaule;

        public VauleMap(String key, Object vaule) {
            this.key = key;
            this.vaule = vaule;
        }
    }
    public void putVaule(VauleMap... vauleMaps){
        SharedPreferences.Editor editor=sharedPreferences.edit();
        for (VauleMap vauleMap:vauleMaps){
            if (vauleMap.vaule instanceof String){
                editor.putString(vauleMap.key,vauleMap.vaule.toString()).commit();
            }
            if (vauleMap.vaule instanceof Boolean){
                editor.putBoolean(vauleMap.key,Boolean.parseBoolean(vauleMap.vaule.toString())).commit();
            }
        }

    }
    public String getString(String key){
        return sharedPreferences.getString(key,null);
    }
    public Boolean getBoolean(String key){
        return sharedPreferences.getBoolean(key,false);
    }
    public void clear(){
        sharedPreferences.edit().clear().commit();
    }
}
